﻿
jQuery(document).ready(function() {

    var URL = document.location + "/GetXMLSchedule";

    scheduler.init('scheduler_here', null, "week");

    $.getJSON(URL, onScheduleLoadSuccess);

})
function onScheduleLoadSuccess(data) {
    var event = null;
    for (var i = 0; i < data.length; i++) {
        event = {
            start_date: new Date(getDateFromFormat(data[i].start_date, "yyyy.MM.d HH.mm.ss")),
            end_date: new Date(getDateFromFormat(data[i].end_date, "yyyy.MM.d HH.mm.ss")),
            text: data[i].text,
            custom_data: data[i].custom_data
        };
        scheduler.addEvent(event);
    }
    scheduler.attachEvent("onEventAdded", addEventToSchedule);

}
function addEventToSchedule(event_id, event_object) {
    var event_length = null;
    if (event_object.event_length !== undefined && event_object.event_length !== null) {
        event_length = event_object.event_length;
    }
    var rec_type = null;
    if (event_object.rec_type !== undefined && event_object.rec_type !== null && event_object.rec_type != "") {
        rec_type = event_object.rec_type;
    }
    var id = event_object.id;
    
    var rusult = {
        "start_date": event_object.start_date.format("yyyy.MM.dd HH.mm.ss"),
        "end_date": event_object.end_date.format("yyyy.MM.dd HH.mm.ss"),
        "event_length": event_length,
        "rec_type": rec_type,
        "text": event_object.text,
        "event_pid": id
    };

    $.post(document.location + "/SaveEvent", rusult);
}



